import 'dart:ui';

class GLScreenFit {
  static double physicalWidth = 0.0;
  static double physicalHeight = 0.0;
  static double screenWidth = 0.0;
  static double screenHeight = 0.0;
  static double dpr = 0.0;
  static double statusTopHeight = 0.0;
  static double rpx = 0.0;
  static double px = 0.0;


  static void initilize ({standarSize = 750}) {

    /// * 1. 物理分辨率
    physicalWidth = window.physicalSize.width;
    physicalHeight = window.physicalSize.height;


    /// * 2. 通过 dpr 计算逻辑像素
    /// 如果想在这个地方获取到逻辑像素，可以使用源码中获取逻辑像素的方法（通过 dpr 计算）
    dpr = window.devicePixelRatio;
    screenWidth = physicalWidth / dpr;
    screenHeight = physicalHeight / dpr;


    /// * 3. 顶部状态栏的高度
    statusTopHeight = window.padding.top / dpr;

    /// * 4. 计算 rpx
    rpx = screenWidth / standarSize;
    px = screenWidth / standarSize * 2;


  }

  static double setRpx(double size) {
    return size * rpx;
  }
   static double setPx(double size) {
    return size * px;
  }
}

/// * 使用
/// width: GLScreenFit.setRpx(400),
/// height: GLScreenFit.setPx(200),
/// 400 * GLScreenFit.rpx